from scipy.interpolate import interp1d
import numpy as np
import pylab as pl
import matplotlib.pyplot as plt
import csv
import math

reader = csv.reader(open("complexity.csv", "rb")) 
#writer = csv.writer(open("complexityLog.csv", "wb"))
#for row in reader:
#    complexityLog = []
#    for i in row:
#        complexityLog.append(math.log((float)(i)))
#    writer.writerow(complexityLog) 

Narray =[]
Narray.append(10)
for j in range(20):
    N = 25 *(j+1)
    Narray.append(N)


m = []
s = []
for row in reader:
    r = []
    for i in range(len(row)):
        r.append((float)(row[i]))
    m.append(np.mean(r))
    s.append(np.std(r))
    
mLog = []
sLog = []
logData = csv.reader(open("complexityLog.csv", "rb")) 
for row in logData:
    r = []
    for i in range(len(row)):
        r.append((float)(row[i]))
    mLog.append(np.mean(r))
    sLog.append(np.std(r))

NarrayLog = []
for i in Narray:
    NarrayLog.append(math.log(i))

fitted = np.polyfit(NarrayLog, mLog, 1)
fittedMean = []

for i in range(8):
    f = fitted[0]*i +fitted[1]
    fittedMean.append(f)

pl.figure()
pl.errorbar(NarrayLog, mLog, yerr = sLog, fmt = 'o-',ecolor='g')
pl.xlabel("Log of Number of snake point")
pl.ylabel("Log Time in s")
pl.title("Time complexity of Snakes and Fitting (Log)")
pl.plot(range(8),fittedMean,'-')
pl.xlabel("log N")
pl.ylabel("log C")
pl.title("Time complexity of Snakes and Fitting (log)")
pl.show()
print fitted

b = fitted[0]
a = math.exp(fitted[1])
print a 
print b
print round(a,2), '* x^' , round(b,2)
x = range(500)
y = a * (x**b) 

plt.figure()
plt.errorbar(Narray, m, yerr = s, fmt = 'o-',ecolor='g')
plt.xlabel("Number of snake point")
plt.ylabel("Time in s")
plt.title("Time complexity of Snakes and Fitting")
plt.plot(x,y)
plt.show()


#just further comment

